home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / spoolaq.exe / SPOOLER.PAS < prev   
Pascal/Delphi Source File  |  1993-06-12  |  26KB  |  599 lines

  1. (* █▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ *)
  2. (* █                                                                █ *)
  3. (* █     S P O O L E R - Object                                     █ *)
  4. (* █                                                                █ *)
  5. (* ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ *)
  6.  
  7. unit Spooler;
  8. { F+}
  9. {$O+}                                  (* can be put in an overlay    *)
  10.  
  11. interface
  12.  
  13. uses
  14.   DOS, Printer,
  15.   Objects, Views, Drivers, App;
  16.  
  17.  
  18. (* ╔════════════════════════════════════════════════════════════════╗ *)
  19. (* ║                                                                ║ *)
  20. (* ║     definition of exported constants                           ║ *)
  21. (* ║                                                                ║ *)
  22. (* ╚════════════════════════════════════════════════════════════════╝ *)
  23. const
  24.   Spool_LPT1 = 1;
  25.   Spool_LPT2 = 2;
  26.   Spool_COM1 = 1;
  27.   Spool_COM2 = 2;
  28.   Spool_COM3 = 3;
  29.   Spool_COM4 = 4;
  30.  
  31.   Spool_300  = 0;
  32.   Spool_600  = 1;
  33.   Spool_1200 = 2;
  34.   Spool_2400 = 3;
  35.   Spool_4800 = 4;
  36.   Spool_9600 = 5;
  37.  
  38.   Spool_Odd  = 0;
  39.   Spool_Even = 1;
  40.  
  41.   Spool_1Stop = 0;
  42.   Spool_2Stop = 1;
  43.  
  44.   Spool_8Bit  = 0;
  45.   Spool_7Bit  = 1;
  46.  
  47.   Spool_FlowXONXOFF = 0;
  48.   Spool_FlowDTR     = 1;
  49.  
  50.  
  51. (* ╔════════════════════════════════════════════════════════════════╗ *)
  52. (* ║                                                                ║ *)
  53. (* ║     definition of object                                       ║ *)
  54. (* ║                                                                ║ *)
  55. (* ╚════════════════════════════════════════════════════════════════╝ *)
  56. type
  57.    PSpooler = ^TSpooler;
  58.    TSpooler = object (TView )
  59.          constructor Init( Rect : TRect; NameOfFile : String );
  60.          destructor  Done;                           virtual;
  61.          procedure   SetParallel( PortNo : word );   virtual;
  62.          procedure   SetSerial(  PortNo,
  63.                                  BaudRate,
  64.                                  DataBits,
  65.                                  StopBits,
  66.                                  Parity,
  67.                                  FlowControl  : word ); virtual;
  68.          procedure   StartSpooling;                  virtual;
  69.          procedure   StopSpooling;                   virtual;
  70.          procedure   CancelSpooling;                 virtual;
  71.          procedure   SpoolOneChar;                   virtual;
  72.          procedure   Draw;                           virtual;
  73.          procedure   Update;                         virtual;
  74.          procedure   UseDOS( Flag : boolean );       virtual;
  75.       private
  76.          Active    : boolean;          (* spool-process is active     *)
  77.          FileName  : PString;          (* name of file to output      *)
  78.          SizeOfFile  : longint;        (* end-marker                  *)
  79.          Remainder   : longint;        (* no. of bytes to handle      *)
  80.          NextChar    : byte;           (* the next char. for output   *)
  81.          NextCharPtr : longint;        (* Ptr. into file              *)
  82.          IsParallel  : boolean;        (* to parallel/serial port ?   *)
  83.          PortAddress : word;           (* address of the port         *)
  84.          SpoolFile   : file;           (* file for reading            *)
  85.          lastTimerTicks : longint;     (* needed for update of no.    *)
  86.          FlowOfControl  : word;        (* which type of control ?     *)
  87.          XOFF_Flag      : boolean;     (* XOFF sent ?                 *)
  88.          DirectHWAccess : boolean;     (* use OUT-instr. or DOS-calls *)
  89.  
  90.          procedure   DeQueue;
  91.          function    StatusLPT : boolean;
  92.          function    COMGetc( COMx : word) : word;
  93.          function    COMPutc(COMx:word; CommandChar:byte) : word;
  94.          function    COMPutC_DTR(COMx:word; CommandChar:byte) : word;
  95.    end;
  96.  
  97.  
  98. implementation
  99. (* ╔════════════════════════════════════════════════════════════════╗ *)
  100. (* ║                                                                ║ *)
  101. (* ║     definition of private constants                            ║ *)
  102. (* ║                                                                ║ *)
  103. (* ╚════════════════════════════════════════════════════════════════╝ *)
  104. const 
  105.     XON  = #$11;
  106.     XOFF = #$13;
  107.  
  108. (* ╔════════════════════════════════════════════════════════════════╗ *)
  109. (* ║                                                                ║ *)
  110. (* ║     the Spooler-object                                         ║ *)
  111. (* ║                                                                ║ *)
  112. (* ╚════════════════════════════════════════════════════════════════╝ *)
  113. (* ┌────────────────────────────────────────────────────────────────┐ *)
  114. (* │                                                                │ *)
  115. (* │     construct the Spool-object                                 │ *)
  116. (* │                                                                │ *)
  117. (* └────────────────────────────────────────────────────────────────┘ *)
  118. constructor TSpooler.Init( Rect : TRect; NameOfFile : String );
  119. begin
  120.     TView.Init( Rect );
  121.     FileName := NewStr( NameOfFile );
  122.     Active   := false;
  123.     NextCharPtr := 0;
  124.     NextChar    := 0;
  125.     SizeOfFile  := 0;
  126.     lastTimerTicks := 0;
  127.     IsParallel  := true;               (* default: parallel           *)
  128.     PortAddress := MemW[$40:8];        (*          = LPT1             *)
  129.     DirectHWAccess := true;
  130. end;
  131.  
  132. (* ┌────────────────────────────────────────────────────────────────┐ *)
  133. (* │                                                                │ *)
  134. (* │     remove Spool-object                                        │ *)
  135. (* │                                                                │ *)
  136. (* └────────────────────────────────────────────────────────────────┘ *)
  137. destructor TSpooler.Done;
  138. var
  139.     f : file;
  140. begin
  141.     if Active then
  142.         CancelSpooling;
  143.     DisposeStr( FileName );
  144.     TView.Done;
  145. end;
  146.  
  147. (* ┌────────────────────────────────────────────────────────────────┐ *)
  148. (* │                                                                │ *)
  149. (* │     init of parallel interface                                 │ *)
  150. (* │                                                                │ *)
  151. (* └────────────────────────────────────────────────────────────────┘ *)
  152. procedure TSpooler.SetParallel( PortNo : word );
  153. begin
  154.     IsParallel  := true;
  155.     PortAddress := MemW[$40:(3+PortNo) shl 1];
  156. end;
  157.  
  158. (* ┌────────────────────────────────────────────────────────────────┐ *)
  159. (* │                                                                │ *)
  160. (* │     init of serial interface                                   │ *)
  161. (* │                                                                │ *)
  162. (* └────────────────────────────────────────────────────────────────┘ *)
  163. procedure TSpooler.SetSerial( PortNo,
  164.                               BaudRate,
  165.                               DataBits,
  166.                               StopBits,
  167.                               Parity,
  168.                               FlowControl  : word );
  169. var
  170.     CommRegs : Registers;
  171. begin
  172.     IsParallel    := false;
  173.     PortAddress   := MemW[$40:(PortNo-Spool_COM1) shl 1];
  174.     FlowOfControl := FlowControl;
  175.     XOFF_Flag     := false;            (* status = XON                *)
  176.     with CommRegs do
  177.     begin
  178. (*  interpretation: look at BIOS, INT 14H, function 0 = init          *)
  179.         AH := 0;
  180.         case BaudRate of
  181.         { Spool_110  :  AL := $00; }
  182.         { Spool_150  :  AL := $20; }
  183.           Spool_300  :  AL := $40;
  184.           Spool_600  :  AL := $60;
  185.           Spool_1200 :  AL := $80;
  186.           Spool_2400 :  AL := $A0;
  187.           Spool_4800 :  AL := $C0;
  188.           Spool_9600 :  AL := $E0;
  189.         end;
  190.         case Parity of
  191.           Spool_Odd  :  AL := AL or $08;
  192.           Spool_Even :  AL := AL or $18;
  193.         end;
  194.         case StopBits of
  195.           Spool_1Stop :  AL := AL or $00;
  196.           Spool_2Stop :  AL := AL or $04;
  197.         end;
  198.         case DataBits of
  199.           Spool_8Bit